import tushare as ts
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
print(1)

# pro = ts.pro_api('3687fa640a51b5aeb6e0431fb9ae157e5069418c18bc55d621d7928c')
# df = pro.coin_bar(exchange='okex', ts_code='BTC_USDT', freq='1min', start_date='2020-04-01 00:00:01', end_date='2020-04-22 19:00:00')

# df=ts.get_k_data('600519',start='1988-01-01')
# df.to_csv('600519.csv')
df=pd.read_csv('600519.csv',index_col='date',parse_dates=['date'])[['open','close','high','low']]
#当日涨幅大于0.03
df1=df[(df['close']-df['open'])/df['open']>=0.03]
date=df.index
#当日open比前日close跌0.02
df2=df[(df['open']-df['close'].shift(1))/df['close'].shift(1)<=-0.02]
#剔除不完整数据
df=df['2001-09':'2020-09']
print(df)
df_monthly=df.resample('M').first()
df_yearly=df.resample('A').last()[:-1]
#每月第一个交易日买入1手股票，每年最后一个交易日全部卖出
cost_money=0
hold=0
for year in range(2001,2021):
    cost_money+= df_monthly[str(year)]['open'].sum()*100
    hold+=len(df_monthly[str(year)]['open'])*100
    if year != 2020:
        cost_money-= df_yearly[str(year)]['open'][0]*hold
        hold=0
        print(-cost_money)
cost_money-=hold*df['open'][-1]
print(-cost_money)